<%@ include file="/common/taglibs.jsp"%>
<%@ taglib tagdir="/WEB-INF/tags/other" prefix="other"%>
<probiz:pageHeading pageHeadingKey="paymentMethodList.title" />
<content tag="buttons">
	<probiz:iconBtn btnType="add" onclick="showAddPaymentMethodDialog();" />
	<probiz:iconBtn btnType="save" onclick="batchUpdatePaymentMethods();" />
</content>

<form class="mainForm" name="paymentMethodsForm" id="paymentMethodsForm" method="Post">
	<input type="hidden" name="doAction" value=""/>
	<div class="top clearfix">
			<ul class="tab">
				<li class="curr"><span><fmt:message key="menu.paymentMethodList"/></span></li>
			</ul>
		</div>
	<div class="data">
		<c:set var="checkAll">
			<input type="checkbox" name="allbox" onclick="checkAllOption(this)" class="checkbox" />
			<fmt:message key="paymentMethod.status"/>
		</c:set>
		<display:table name="${paymentMethodList}" cellspacing="0" cellpadding="0" uid="paymentMethodItem" class="list_table" style="width:100%;">
			<display:column title="${checkAll}" style="width:7%">
				<input type="hidden" name="paymentMethodId" value="<c:out value="${paymentMethodItem.paymentMethodId}"/>"/>
				<!-- uid+'_rowNum'是display:table定义的一个变量 -->
				<other:statusCheckBox id="status${paymentMethodItem_rowNum}" name="status" value="${paymentMethodItem.status}"/>
			</display:column>
		
		    <display:column  decorator="com.probiz.estore.core.decorator.TblColumnDecorator" titleKey="paymentMethod.paymentMethodName">
				<input type="text" class="inputtxt" name="paymentMethodName" value="${paymentMethodItem.paymentMethodName}" size="32"/>
			</display:column>
		
		    <display:column style="width:25%"  titleKey="paymentMethod.paymentMethodDetail"
		        decorator="com.probiz.estore.core.decorator.TblColumnDecorator">
		        <textarea cols="45" rows="3" name="paymentMethodDetail" class="textareatxt" id="detail${paymentMethodItem_rowNum}">${paymentMethodItem.paymentMethodDetail}</textarea>
			</display:column>
			<display:column style="width:25%" titleKey="paymentMethod.helpLink"
		        decorator="com.probiz.estore.core.decorator.TblColumnDecorator">
		        <textarea cols="45" rows="3" name="helpLink" class="textareatxt" id="helpLink${paymentMethodItem_rowNum}">${paymentMethodItem.helpLink}</textarea>
			</display:column>
		    <display:column style="width:7%" decorator="com.probiz.estore.core.decorator.TblColumnDecorator" titleKey="paymentMethod.protocol">
				<select name="protocol" class="selecttxt">
					<option value="HTTP" <c:if test="${paymentMethodItem.protocol=='HTTP'}"><c:out value="selected='selected'"/></c:if> >HTTP</option>
					<option value="HTTPS" <c:if test="${paymentMethodItem.protocol=='HTTPS'}"><c:out value="selected='selected'"/></c:if>>HTTPS</option>
				</select>
			</display:column>
		
			<display:column  style="width:7%"
		        decorator="com.probiz.estore.core.decorator.TblColumnDecorator" titleKey="paymentMethod.sortOrder">
				<input type="text" class="inputtxt" name="sortOrder" value="${paymentMethodItem.sortOrder}" size="6"/>
			</display:column>
		
		    <display:column  style="width:7%"
		        decorator="com.probiz.estore.core.decorator.TblColumnDecorator" titleKey="paymentMethod.paymentMethodType">
				<fmt:message key="paymentMethod.paymentMethodType${paymentMethodItem.paymentMethodType}"/>
			</display:column>
		
			<display:column titleKey="public.management" style="width:8%">
				<c:if test="${paymentMethodItem.paymentGatewayId!=null}">
					<a href="<c:url value="paymentMethod.html?doAction=config&paymentGatewayId=${paymentMethodItem.paymentGatewayId}"/>"><b><fmt:message key="paymentMethod.config"/></b></a>
					|<a onclick="return confirm('<fmt:message key="paymentMethod.delete.confirm"/>');" href="<c:out value="paymentMethod.html?paymentMethodId=${paymentMethodItem.paymentMethodId}&paymentGatewayId=${paymentMethodItem.paymentGatewayId}&doAction=delete"/>"><fmt:message key="button.delete"/></a>
				</c:if>&nbsp;
			</display:column>
		</display:table>
	</div>
</form>


<script type="text/javascript">
$j(document).ready(function(){
	highlightTableRows("paymentMethodItem");
	
	__FMTExtend = {
		paymentMethod_error_sortOrder:"<fmt:message key="paymentMethod.error.sortOrder"/>",
		paymentMethod_selectOneGateway:"<fmt:message key="paymentMethod.selectOneGateway"/>"
	};
	$j.extend(__FMT, __FMTExtend); 	

	var paymentMethodDetail= $j("textarea[name='paymentMethodDetail']");
	for ( var a= 0; a < paymentMethodDetail.length; a++) {
		var id = $j(paymentMethodDetail[a]).attr("id");
		applyValidate($(id),"maxlength=1024"); 
	}

	var helpLink= $j("textarea[name='helpLink']");
	for ( var a= 0; a < helpLink.length; a++) {
		var id = $j(helpLink[a]).attr("id");
		applyValidate($(id),"maxlength=512"); 
	}
});
//批量更新支付方式
function batchUpdatePaymentMethods(){
	if(validateForm()){
		if(confirm(__FMT.common_message_confirmSave)){
			var paymentMethodIds=document.getElementsByName("paymentMethodId");
			if(paymentMethodIds==null||paymentMethodIds.length==0)return;
			
			var sortOrders=document.getElementsByName("sortOrder");
			var rex=/^-?\d+$/;
			for(var i=0;i<sortOrders.length;i++){
				if(rex.test(sortOrders[i].value)==false){
					alert(__FMT.paymentMethod_error_sortOrder);
					sortOrders[i].focus();
					return;
				}
			}
			var form=document.forms["paymentMethodsForm"];
			form.doAction.value="multiSave";
			form.submit();
		}
	}
}
//显示paymentGayway dialog
function showAddPaymentMethodDialog(){
	dlgaddPaymentMethodDlg_show();
}
//关闭paymentGayway dialog
function closeAddPaymentMethodDialog(){
	dlgaddPaymentMethodDlg_close();
}
//新增支付方式
function addPaymentMethod(){
	var form=document.forms["paymentGatewayForm"];
	form.doAction.value="add";
	var selectedIndex=$('paymentGatewayId').selectedIndex;
	if($('paymentGatewayId').value==-1){
		alert(__FMT.paymentMethod_selectOneGateway);
		return false;
	}
	form.paymentGatewayName.value=$('paymentGatewayId').options[selectedIndex].text;
	form.submit();		
}
</script>


<fmt:message key="button.confirm" var="buttonConfirm"/>
<fmt:message key="button.cancel" var="buttonCancel"/>
<fmt:message key="paymentGatewayList.addNew" var="title"/>
<probiz:ui_dialog id="addPaymentMethodDlg" width="500" height="120" title="${title}" buttons="'${buttonConfirm}':addPaymentMethod,'${buttonCancel}':closeAddPaymentMethodDialog">
	<form id="paymentGatewayForm" name="paymentGatewayForm">
		<input type="hidden" name="doAction" value=""/>
		<div>
			<table  width="100%" border="0" cellspacing="0" cellpadding="0" class="com_modi_table">
			  <tr>
			    <th height="30px" width="150" align="left"><fmt:message key="paymentGatewayList.select"/></th>
			    <td>
					<select id="paymentGatewayId" name="paymentGatewayId" style="width:250px" class="selecttxt">
						<option value="-1"><fmt:message key="common.message.pleaseSelect"/></option>
						<c:forEach items="${paymentGatewayList}" var="paymentGateway">
							<option value="${paymentGateway.paymentGatewayId}">${paymentGateway.paymentGatewayName}</option>
						</c:forEach>
					</select>
					<input type="hidden" name="paymentGatewayName" value=""/>
				</td>
			  </tr>
			</table>
		</div>
	</form>
</probiz:ui_dialog>
